<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>分类列表</h2>
    </div>

    <div class="cf">
        <a class="btn" href="{:U('GoodsCategory/add', array('pid'=>$pid))}">新 增</a>
        <button class="btn ajax-post confirm" url="{:U('del')}" target-form="ids">删 除</button>
        <!-- <button class="btn list_sort" url="{:U('sort?group='.I('group'),'','')}">排序</button> -->
        
        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="title" class="search-input" value="{:I('title')}" placeholder="请输入品牌名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>

    <div class="data-table table-striped">
        <table>
            <thead>
                <tr>
                    <th class="row-selected">
                        <input class="checkbox check-all" type="checkbox">
                    </th>
                    <th>ID</th>
                    <th>分类名称</th>
                    <th>上级菜单</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th>分类级别</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <notempty name="list">
                <volist name="list" id="info">
                    <tr>
                        <td><input class="ids row-selected" type="checkbox" name="id[]" value="{$info.id}"></td>
                        <td>{$info.id}</td>
                        <td>{$info.title}</td>
                        <td>{$topList[$info['pid']]['title']}</td>
                        <td>{$info.sort}</td>
                        <td>{$info.status|get_status_title}</td>
                        <td>{$info.lev}级分类</td>
                        <td>
                            <if condition="$info['lev'] lt 3 ">
                                <a href="{:U('GoodsCategory/add', array('pid'=>$info['id']))}">添加子分类</a>
                                <a href="{:U('GoodsCategory/index', array('pid'=>$info['id']))}">查看子菜单</a>
                            </if>
                            
                            <eq name="info.lev" value="3">
                                <a title="属性" href="{:U('GoodsAttribute/index?pid='.$info['id'])}">分类属性</a>
                                <a title="规格" href="{:U('GoodsSpecs/index?pid='.$info['id'])}">分类规格</a>
                            </eq>
                            
                            <a title="编辑" href="{:U('edit?id='.$info['id'])}">编辑</a>
                            <eq name="info.status" value="1">
                                <a href="{:U('GoodsCategory/status?id='.$info['id'].'&status='.abs(1-$info['status']))}" class="ajax-get">禁用</a>
                            <else/>
                                <a href="{:U('GoodsCategory/status?id='.$info['id'].'&status='.abs(1-$info['status']))}" class="ajax-get">启用</a>
                            </eq>
                            <a class="confirm ajax-get" title="删除" href="{:U('del?id='.$info['id'])}">删除</a>
                        </td>
                    </tr>
                </volist>
                <else/>
                <td colspan="7" class="text-center"> aOh! 暂时还没有内容! </td>
                </notempty>
            </tbody>
        </table>
        <!-- 分页 -->
        <div class="page">
            {$_page}
        </div>
    </div>
</block>

<block name="script">
<script type="text/javascript">
$(function(){
    //搜索功能
    $("#search").click(function(){
        var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
        window.location.href = url;
    });
    //回车搜索
    $(".search-input").keyup(function(e){
        if(e.keyCode === 13){
            $("#search").click();
            return false;
        }
    });
    //点击排序
    $('.list_sort').click(function(){
        var url = $(this).attr('url');
        var ids = $('.ids:checked');
        var param = '';
        if(ids.length > 0){
            var str = new Array();
            ids.each(function(){
                str.push($(this).val());
            });
            param = str.join(',');
        }

        if(url != undefined && url != ''){
            window.location.href = url + '/ids/' + param;
        }
    });

    highlight_subnav('{:U('GoodsCategory/index')}');
});
</script>
</block>